package com.atguigu.java;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorTest {
    @Test
    public void test() {
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        Person p = new Person("jerry", 20);
        coll.add(p);
        coll.add(new String("tom"));
        coll.add(false);
        Iterator iterator = coll.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
    @Test
    public void test1(){
        Collection coll=new ArrayList();
        coll.add(123);
        coll.add(456);
        Person p=new Person("jerry",20);
        coll.add(p);
        coll.add(new String("tom"));
        coll.add(false);
        Iterator iterator = coll.iterator();
        while(iterator.hasNext()){
            Object obj = iterator.next();
            if("tom".equals(obj)){
                iterator.remove();
            }

        }

        iterator=coll.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
